package com.xy.controller.admin;

import com.xy.base.RestResponse;
import com.xy.domain.Major;
import com.xy.repository.MajorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/api/admin/major")
public class MajorController {

    @Autowired
    private MajorMapper majorMapper;

    // @GetMapping("/list/{id}")
    // public RestResponse<Major> listMajor(@PathVariable("id") Integer id) {
    //     return RestResponse.ok(majorMapper.selectByPrimaryKey(id));
    // }

    @GetMapping("/list/{departId}")
    public RestResponse<List<Major>> listMajors(@PathVariable Integer departId) {
        return RestResponse.ok(majorMapper.listByDepId(departId));
    }

    @PutMapping("/update")
    public RestResponse<Void> updateMajor(@RequestBody Major major) {
        majorMapper.updateByPrimaryKey(major);
        return RestResponse.ok();
    }

    @PostMapping("/add")
    public RestResponse<Void> addMajor(@RequestBody Major major) {
        majorMapper.insert(major);
        return RestResponse.ok();
    }
}
